#!/usr/bin/env python

import pygtk
import gtk

class Hello:
	def hello(self, widget, data=None):
		print "hello world"

	def delete_event(self, widget, event, data=None):
		print "delete Event occurred"
		return False
	
	def destroy(self, widget, data=None):
		gtk.main_quit()
	
	def createButton_with_image(self, imagepath):
		button = gtk.Button()
		image = gtk.Image()
		image.set_from_file(imagepath)
		button.add(image)
	
		return button

	def createKeyBoard(self, type):
		if "T9" == type:
			self.table = gtk.Table(4, 3, True)
			self.window.add(self.table)

			self.text_button = gtk.Button()
			self.table.attach(self.text_button, 0, 3, 0, 1)

			index = 1
			for i in range(3):
				for j in range(3):
					loadres = "res/num%s.png" %index
					index = index + 1
					button = self.createButton_with_image(loadres)
					self.table.attach(button, j, j+1, i+1, i+2)

	def __init__(self):
		print "create hello object"
		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		self.window.connect("delete_event", self.delete_event)
		self.window.connect("destroy", self.destroy)
		self.window.set_border_width(10)
		self.window.set_default_size(270,300)
		self.createKeyBoard("T9");
		self.window.show_all()


	def main(self):
		gtk.main()


if __name__ == '__main__':
	print "begin to create"
	hello = Hello()
	print "begin to run"
	hello.main()
